<template>
  <ContainerGroup>
    <Container>
      <span style="color:#909399">是否跨病区：</span>
      <el-select v-model="bedUggIeBC" inline size="mini" @change="bedUggIeBCChange">
        <el-option v-for="(item,index) in bedUggIeBCList" :key="index" :value="item.value" :label="item.label" />
      </el-select>
      <div style="display:inline-block;margin-left:12px">
        <FilterForm
          ref="filterForm"
          :elements="filterElements"
          :button-list="buttonList"
        />
      </div>
    </Container>
    <Container height="fill" style="height:calc(100% - 96px)">
      <OperationContainer align="right" style="margin-bottom: 10px">
        <Button icon="export" @click="_DownLoad">导出</Button>
      </OperationContainer>
      <div class="table-box" style="height:calc(100% - 100px);overflow-y:auto;margin-bottom: 10px;">
        <el-table
          v-loading="loading"
          :data="tableData"
          stripe
          border
          :header-cell-style="{ background:'#f5f7fa' }"
          style="width: 100%"
        >
          <!-- <el-table-column type="selection" align="center" width="55" /> -->
          <el-table-column type="index" align="center" label="序号" width="55" />
          <el-table-column prop="inDate" align="center" label="登记日期" width="240" />
          <el-table-column prop="name" align="center" label="姓名" />
          <el-table-column prop="sex" align="center" label="性别">
            <template slot-scope="scope">
              {{ scope.row.sex === '1' ? '男' : '女' }}
            </template>
          </el-table-column>
          <el-table-column prop="deptName" align="center" label="拟入院科室" />
          <el-table-column prop="diagName" align="center" label="入院诊断" />
          <!-- <el-table-column prop="examineListName" align="center" label="核酸" /> -->
          <el-table-column prop="chargeDocName" align="center" label="主治医师" />
          <el-table-column prop="nurseCellName" align="center" label="实际入住病区" />
          <el-table-column prop="bedNo" align="center" label="处理结果" />
<!-- 
           <el-table-column prop="patientTag" align="center" label="患者分属">
            <template
              slot-scope="scope"
            >
              <span v-if="scope.row.patientTag==='2'">院前患者</span>
              <span v-if="scope.row.patientTag==='0'">''</span>
            </template>
          </el-table-column>
             <el-table-column prop="ifGy" align="center" label="集管床位状态">
            <template
              slot-scope="scope"
            >
              <span v-if="scope.row.ifGy==='0'">当前为非集管床位</span>
              <span v-if="scope.row.ifGy==='1'">''</span>
            </template>
          </el-table-column> -->
          <el-table-column prop="isBedUggIeBC" align="center" label="是否跨区">
            <template
              slot-scope="scope"
            >
              <span v-if="scope.row.isBedUggIeBC==='0'">否</span>
              <span v-if="scope.row.isBedUggIeBC==='1'">是</span>
            </template>
          </el-table-column>
          <el-table-column prop="yard" align="center" label="所属院区">
            <template
              slot-scope="scope"
            >
              <span v-if="scope.row.yard==='1'">三香</span>
              <span v-if="scope.row.yard==='2'">浒关</span>
            </template>
          </el-table-column>
          <el-table-column prop="beizhu" align="center" label="备注" />
        </el-table>
      </div>
      <div style="text-align: right;padding:12px 0 0 0">
        <el-pagination
          :current-page.sync="currentPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          layout="prev, pager, next, sizes, total"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </Container>
  </ContainerGroup>
</template>

<script>
import ContainerGroup from '../../components/ContainerGroup.vue'
import {
  getBedUggIeCW,
  getBedUggIeCWDownLoadExcel
} from '../../utils/apis/preparedness'
export default {
  name: 'CheckReport',
  components: { ContainerGroup },
  data() {
    return {
      total: 0,
      pageSize: 20,
      currentPage: 1,
      loading: false,
      // tableData: [
      //   {
      //     name: '郑满珍',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2',
      //     beizhu: '1.三香路院区：苏州市姑苏区三香路1055号\n    2.异地医保患者请先至参保地备案后办理入院'
      //   },
      //   {
      //     name: '刘亦菲',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   },
      //   {
      //     name: '赵露思',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   },
      //   {
      //     name: '新垣结衣',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   },
      //   {
      //     name: '石原里美',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   },
      //   {
      //     name: '能年玲奈',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   },
      //   {
      //     name: '长泽雅美',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   },
      //   {
      //     name: '张佳宁',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   },
      //   {
      //     name: '郑满珍',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2',
      //     beizhu: '1.三香路院区：苏州市姑苏区三香路1055号\n    2.异地医保患者请先至参保地备案后办理入院'
      //   },
      //   {
      //     name: '刘亦菲',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   },
      //   {
      //     name: '赵露思',
      //     sex: '2',
      //     inDate: '2021-10-28 21:45:37',
      //     deptCode: '1035',
      //     deptName: '骨外科',
      //     bedNo: '26110B1161',
      //     nurseCellCode: '2611',
      //     nurseCellName: '西十一病区',
      //     chargeDocName: '陆政峰',
      //     checked: false,
      //     diagName: '腰椎骨折',
      //     isBedUggIeBc: '2'
      //   }
      // ],
      tableData: [],
      filterElements: [
        {
          key: 'date',
          type: 'DatePicker',
          mode: 'daterange',
          label: '日期',
          value: [],
          width: 300
        }
      ],
      buttonList: [
        {
          label: '查询',
          type: 'primary',
          icon: 'search',
          handlerClick: this.handerSearch
        },
        {
          label: '重置',
          type: 'info',
          icon: 'reset',
          handlerClick: this.handlerReset
        }
      ],
      dateRange: [],
      bedUggIeBC: '2',
      bedUggIeBCList: [
        {
          label: '全部',
          value: '2'
        },
        {
          label: '是',
          value: '1'
        },
        {
          label: '否',
          value: '0'
        }
      ]
    }
  },
  mounted() {
    this.getDate()
    this._getData()
    // this.handerSearch()
  },
  methods: {
    formatDate(date, type) {
      const year = date.getFullYear()
      const month = (date.getMonth() + 1) > 9 ? date.getMonth() + 1 : `0${date.getMonth() + 1}`
      const day = date.getDate() > 9 ? date.getDate() : `0${date.getDate()}`

      if (type === 1) {
        return `${year}-${month}-${day}`
      } else {
        return `${year}-${month}-${day}`
      }
    },
    getDate() {
      let now = new Date()
      let aWeekAgo = new Date(now - 1000 * 3600 * 24 * 7)
      now = this.formatDate(now, 2)
      aWeekAgo = this.formatDate(aWeekAgo, 1)
      this.dateRange = []
      this.dateRange.push(aWeekAgo, now)
      this.filterElements[0].value = []
      this.filterElements[0].value.push(aWeekAgo, now)
    },
    bedUggIeBCChange() {
      this._getData()
    },
    _getData() {
      // this.loading = true
      const params = {
        startDate: this.dateRange.length ? `${this.dateRange[0]} 00:00:00` : '',
        endDate: this.dateRange.length ? `${this.dateRange[1]} 23:59:59` : '',
        isBedUggIeBC: this.bedUggIeBC,
        pageIndex: this.currentPage,
        pageSize: this.pageSize
      }
      console.log(params)
      getBedUggIeCW(params).then(res => {
        if (res.data.code === 200) {
          this.tableData = res.data.data.list
          this.loading = false
          this.total = res.data.data.total
        } else {
          this.loading = false
          this.$message.error(res.data.message)
        }
      })
    },
    handerSearch(val) {
      if (val.date) {
        this.dateRange = val.date
      }
      this._getData()
    },
    handlerReset() {
      this.getDate()
      this.$refs.filterForm.reset()
      this.bedUggIeBC = '2'
    },
    _DownLoad() {
      const params = {
        startDate: this.dateRange.length ? `${this.dateRange[0]} 00:00:00` : '',
        endDate: this.dateRange.length ? `${this.dateRange[1]} 23:59:59` : '',
        isBedUggIeBC: this.bedUggIeBC,
        pageIndex: this.currentPage,
        pageSize: this.pageSize
      }
      getBedUggIeCWDownLoadExcel(params).then(res => {
        // if (res.data.code === 200) {
        const blob = new Blob([res.data])
        const fileName = '日报表(院前)' + '.xlsx'
        const URL = window.URL || window.webkitURL || window.moxURL
        if ('download' in document.createElement('a')) {
          // 非IE下载
          const elink = document.createElement('a')
          elink.download = fileName // 命名下载名称
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob) // 表示一个指定的file对象或Blob对象
          document.body.appendChild(elink)
          elink.click() // 点击触发下载
          URL.revokeObjectURL(elink.href) // 释放URL 对象
          document.body.removeChild(elink)
        } else {
          // IE10+下载
          navigator.msSaveBlob(blob, fileName)
        }
        // }
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this._getData()
    },
    handleCurrentChange(val) {
      this.pageIndex = val
      this._getData()
    },
    handleChange(val) {
      console.log(val)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
